#include "stdafx.h"
#include "ui_disk_files_manager.h"

_SSL_BEGIN
_SSUIL_BEGIN

UIDiskFilesManager::UIDiskFilesManager(int id)
{
	id_ = id;
}

UIDiskFilesManager::~UIDiskFilesManager()
{

}

unsigned char* UIDiskFilesManager::GetFileBuffer(const tchar *file,
	ssbin &bin, size_t extra_bytes, int id /*= 0*/)
{
	bin.set_size(0);
	if(id != id_)
	{
		if(upper_disk_managers_.find(id) == upper_disk_managers_.end())
			return NULL;
		if(upper_disk_managers_[id] == NULL)
			return NULL;
		return upper_disk_managers_[id]->GetFileBuffer(file, bin, extra_bytes, 0);
	}

	tstring file_path = base_path_;
	file_path_append(file_path, file);
	if(!file_readbinary_w(auto_cvt(file_path.c_str()).c_wstr(), bin, extra_bytes))
		return NULL;
	return bin.ptr();
}

void UIDiskFilesManager::SetUpperDiskFilesManager(IUIDiskFilesManagerInterface *upper_disk_files_manager,
	int id)
{
	if(upper_disk_files_manager == NULL)
	{
		IUIDiskFilesManagerInterfaceAutoPtrs::iterator iter = upper_disk_managers_.find(id);
		if(iter != upper_disk_managers_.end())
			upper_disk_managers_.erase(iter);
	}else
	{
		upper_disk_managers_[id] = upper_disk_files_manager;
	}
}

void UIDiskFilesManager::SetBasePath(const tstring &path)
{
	base_path_ = path;
}

_SSUIL_END
_SSL_END

